package com.bjsxt.usersCenter.head.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.bjsxt.usersCenter.users.pojo.AUsers;
@Component("authIntercrptor")
public class AuthIntercrptor extends HandlerInterceptorAdapter
{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		
		String info="";
		HttpSession session=request.getSession();
		
		
		AUsers users=(AUsers) session.getAttribute("users");
		
		if(users!=null)
		{
			session.removeAttribute("info");
			return true;
		}
		info="非法访问，请先登录";
		
		session.setAttribute("info", info);
		response.sendRedirect(request.getContextPath()+"/login.htm");
		return false;
	}
	
}
